import socket
import time
# 通信协议
# 字段以逗号隔开，以分号终止
# 组成形式：命令类型（int），负载数据（多个字段以逗号分隔）；
# 示例：1,0,0,0,3.14,0,0;   命令类型为1：表示发送位姿值，具体位姿值为：0,0,0,3.14,0,0

def TestClient():
    server_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_client.connect(("localhost", 8888))

    num_array = [1.2, 3.5, 56, 78.34, 39.2]
    # 数据包命令类型
    info = "1,"
    # 位姿值
    for num in num_array:
        info += str(num)
        info += ","
    info = info[:-1]
    # 数据包终止符号  分号
    info += ";"
    while True:
        server_client.send(bytes(info, encoding='utf-8'))
        print("send   : ", info)
        # recv_str = server_client.recv(1024)
        # if not recv_str:
        #     break
        # print("receive: ", recv_str.decode("utf-8"))
        # time.sleep(2.0)

    server_client.close()
    print("server end, exit!")
    exit()


if __name__ == '__main__':
    TestClient()

